package com.jbm.jbmsupplier.zp.FactouryActivity;

import android.content.Context;
import android.content.Intent;

import com.jbm.jbmsupplier.zp.entity.Buddy_ListData;
import com.jbm.jbmsupplier.zp.entity.ChatMsgEntity;
import com.jbm.jbmsupplier.zp.utils.ClassUser;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by 家帮忙 on 2017/7/11.
 */

public class MyNewFile implements ChatSaveMessage {
    private ArrayList<HashMap<String, String>> list1;
    private  Context context;
    private ArrayList<ChatMsgEntity> arrayList;
    private ClassUser ClassUser;
    private final int USERMASSAGES=0x004;
    private final int TIME=0x0001;
    private Buddy_ListData namse;

    @Override
    public void setDataChat(Context context, ArrayList<ChatMsgEntity> arrayList, ClassUser ClassUser) {
        this.context=context;
//        if (arrayList.get(0).getTags()==1) {
//            MySqliteUtlis.GetInstan(context).InsertGroadTable(CHATGROUD, MySqliteUtlis.GetInstan(context).SelectName(GROUD, arrayList.get(0).getCgid()) + "", OHInterface.getG_server().logo, arrayList.get(0).getDate(), "", "", arrayList.get(0).getTo_id(), -1, -1, -0, "", arrayList.get(0).getRoute(), "", "", 1, "", "", 10, arrayList.get(0).getCgid(), 1,"true",ClassUser.getLogin());
//        }else{
//            namse = MySqliteUtlis.GetInstan(context).showFriendsToID(BUDDY, arrayList.get(0).getTo_id(), ClassUser.getLogin());
//            if (namse==null) {
//                MySqliteUtlis.GetInstan(context).StoringBuddydata(BUDDY , arrayList.get(0).getTo_id(),"默认名(家)","","","","","","","",1,ClassUser.getLogin());
//
//                MySqliteUtlis.GetInstan(context).StoringChatData(CHAT, arrayList.get(0).getTo_id(), OHInterface.getG_server().logo, "", arrayList.get(0).getDate(), "", arrayList.get(0).getRoute(), "", "", "", "", "", "", "", "",10, 0,"true",ClassUser.getLogin());
//            }else{
//                MySqliteUtlis.GetInstan(context).StoringChatData(CHAT, arrayList.get(0).getTo_id(), OHInterface.getG_server().logo, "", arrayList.get(0).getDate(), namse.getNickname(), arrayList.get(0).getRoute(), "", "", "", "", "", "", "", "",10, 0,"true",ClassUser.getLogin());
//            }
//            ArrayList<String> als = MySqliteUtlis.GetInstan(context).showaRecentContactsid(RECENT,arrayList.get(0).getTo_id(),ClassUser.getLogin());
//            if (!als.toString().contains(arrayList.get(0).getTo_id()+"")) {
//                MySqliteUtlis.GetInstan(context).StoringRecentID(RECENT, arrayList.get(0).getTo_id(),ClassUser.getLogin(), arrayList.get(0).getDate());
//            }else if (als.toString()==null){
//                MySqliteUtlis.GetInstan(context).StoringRecentID(RECENT ,arrayList.get(0).getTo_id(),ClassUser.getLogin(), arrayList.get(0).getDate());
//            }
//    }
        setBroadCase(10, arrayList);
        arrayList.remove(0);

    }

    private void setBroadCase(int id,ArrayList<ChatMsgEntity> arrayList){
        Intent intent = new Intent();
     intent.putExtra("messageFlag", id);
        if (arrayList.get(0).getTags()==1){
            intent.putExtra("cgid", arrayList.get(0).getCgid());
            intent.putExtra("tags",1);
        }else {
            intent.putExtra("account_id", arrayList.get(0).getTo_id());
        }
     intent.putExtra("Route", arrayList.get(0).getRoute());
     intent.putExtra("Date", arrayList.get(0).getDate());
     intent.setAction("MSG");

        context.sendBroadcast(intent);
    }
}
